/*
 * Background Flickr: Copyright (C) 2009  Craig McNicholas
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ddw.app.bflickr.flickr.api;

import com.ddw.app.bflickr.flickr.api.utils.EmailAddress;
import com.ddw.app.bflickr.logging.Log;
import com.ddw.app.bflickr.logging.LogFactory;

/**
 * Class to hold a flickr accounts information.
 * Accounts must have an NSID according to flickr whilst
 * email address and username's may change.
 * @author craig
 *
 */
public class FlickrAccount {

	private Log log = LogFactory.createInstance(this.getClass());
	private String nsid;
	private EmailAddress email = null;
	private String username = null;
	
	/**
	 * Creates a new flickr account instance
	 * @param NSID the unique ID given by flickr
	 * @param username the username of the flickr account
	 * @param email the email address of the flickr account
	 */
	public FlickrAccount(String NSID, String username, EmailAddress email) {
		setNSID(NSID);
		setUsername(username);
		setEmailAddress(email);
	}
	
	/**
	 * Creates a new flickr account instance
	 * @param NSID the unique ID given by flickr
	 * @param username the username of the flickr account
	 */
	public FlickrAccount(String NSID, String username) {
		setNSID(NSID);
		setUsername(username);
	}
	
	/**
	 * Creates a new flickr account instance
	 * @param NSID the unique ID given by flickr
	 * @param email the email address of the flickr account
	 */
	public FlickrAccount(String NSID, EmailAddress email) {
		setNSID(NSID);
		setEmailAddress(email);
	}
	
	/**
	 * Creates a new flickr account instance
	 * @param NSID the unique ID given by flickr
	 */
	public FlickrAccount(String NSID) {
		setNSID(NSID);
	}
	
	/**
	 * Getter of the accounts email address
	 * @return the email address <b>or null</b> if not set
	 */
	public EmailAddress getEmailAddress() {
		return this.email;
	}
	
	/**
	 * Getter of the accounts username
	 * @return the username <b>or null</b> if not set
	 */
	public String getUsername() {
		return this.username;
	}
	
	/**
	 * Getter of the accounts NSID
	 * @return the NSID, <b>it cannot be null</b>
	 */
	public String getNSID() {
		return this.nsid;
	}
	
	/**
	 * Setter of the accounts NSID
	 * @param NSID the NSID to set for the account
	 * @throws IllegalArgumentException when the NSID is null or is empty, <i>flickr account NSID's cannot equal null or be invalid</i>
	 */
	private void setNSID(String NSID) throws IllegalArgumentException {
		if(NSID == null) { 
			log.error("The flickr accounts NSID cannot be null");
			throw new IllegalArgumentException("The flickr accounts NSID cannot be null");
		}
		if(NSID.trim().length() == 0) {
			log.error("The flickr accounts NSID cannot be empty");
			throw new IllegalArgumentException("The flickr accounts NSID cannot be empty");
		}
		this.nsid = NSID;
	}
	
	/**
	 * Setter of the accounts email address
	 * @param email the email address to set
	 * @throws IllegalArgumentException when the email is null or is not in a valid format, <i>flickr account email addresses cannot equal null</i>
	 */
	public void setEmailAddress(EmailAddress email) throws IllegalArgumentException {
		if(email == null) {
			log.error("The flickr accounts email address cannot be null.");
			throw new IllegalArgumentException("The flickr accounts email address cannot be null.");
		}
		this.email = email;
	}

	/**
	 * Setter of the accounts username
	 * @param username the username to set
	 * @throws IllegalArgumentException when the username is null, <i>flickr account usernames cannot equal null</i>
	 */
	public void setUsername(String username) throws IllegalArgumentException {
		if(username == null) {
			log.error("The flickr accounts username cannot be null.");
			throw new IllegalArgumentException("The flickr accounts username cannot be null.");
		}
		if(username.trim().length() == 0) {
			log.error("The flickr accounts username cannot be empty.");
			throw new IllegalArgumentException("The flickr accounts username cannot be empty.");
		}
		this.username = username;
	}
	
}
